﻿using CharacterCreation.Views.Contracts;
using CharacterCreation.Data.Services;
using CharacterCreation.Data.Models;
using System.Collections.ObjectModel;
using System.Linq;

namespace CharacterCreation.Views {
    /// <summary>
    /// The viewmodel 
    /// </summary>
    public class DexterityViewModel : BaseViewModel {

        DexterityService _service = DexterityService.CreateInstance();

        public ObservableCollection<Dexterity> Items {
            get { return new ObservableCollection<Dexterity>(_service.Items.OrderBy(s => s.Level)); }
        }

        public DexterityViewModel() {
            this.Items.CollectionChanged += (s, e) => {
                if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Remove &&
                    (e.OldItems.SyncRoot as System.Object[])[0] != null)
                    Data.DataContext.Delete((e.OldItems.SyncRoot as System.Object[])[0]);
            };
        }
    }
}
